package com.lyj.io.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyj.io.module.sys.dao.SysUserRoleDao;
import com.lyj.io.module.sys.entity.SysUserRole;
import com.lyj.io.module.sys.service.SysUserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 角色接口
 * @author: 李亚杰
 * @version: 1.0
 * @date: 2021/8/19 14:31
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleDao, SysUserRole> implements SysUserRoleService {

    @Override
    public List<String> getRoleIdsByUserId(String userId) {
        QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
        queryWrapper.eq("user_id", userId);
        return this.baseMapper.selectList(queryWrapper).stream().map(item -> item.getRoleId()).collect(Collectors.toList());
    }

    @Override
    public SysUserRole getRoleIdByUserId(String userId) {
        QueryWrapper<SysUserRole> queryWrapper = new QueryWrapper<SysUserRole>();
        queryWrapper.eq("user_id", userId);
        return this.baseMapper.selectOne(queryWrapper);
    }
}
